package com.example.qxfw.jtyb.controller;

import com.example.qxfw.common.SysResult;
import com.example.qxfw.common.entity.zy.Traffic;
import com.example.qxfw.common.entity.zy.TrafficWeatherSta;
import com.example.qxfw.common.util.DateUtil;
import com.example.qxfw.jtyb.service.JtybcxService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Date;
import java.util.List;

@Api(tags = "交通预报-交通预报查询")
@RestController
@CrossOrigin
@RequestMapping("/jtybcx")
public class JtybcxController {
    @Autowired
    private JtybcxService jtybcxService;

    @ApiOperation("获取交通气象站点类型信息")
    @GetMapping("/selectTypeOfTrafficWeatherSta")
    public SysResult selectTypeOfTrafficWeatherSta(){
        List<TrafficWeatherSta> list = jtybcxService.selectTypeOfTrafficWeatherSta();
        return SysResult.success(list);
    }


    @ApiOperation("根据道路类型日期类型时次时效查询交通预报表")
    @GetMapping("/selectByRoadDateTypeNtimesTimecharOfTraffic")
    public SysResult selectByRoadDateTypeNtimesTimecharOfTraffic(
            String roadType, String announcedtime, Integer forecasttype, Integer ntimes, String timechar
    ){
        StringBuilder sb = new StringBuilder();
        sb.append(announcedtime);
        sb.append(" ");
        sb.append(timechar);
        Date date = DateUtil.localDateTimeToDate(DateUtil.stringToLocalDateTime(sb.toString()));
        List<Traffic> list = jtybcxService.selectByRoadDateTypeNtimesTimecharOfTraffic(roadType, date, forecasttype, ntimes);
        return SysResult.success(list);
    }
}
